#!/bin/bash

echo "=== CBR协议性能测试 ==="

# 设置测试参数
N=6
BATCH_SIZE=5000
TX_SIZE=250
R=5
EPOCH=30

echo "测试参数: N=$N, batchsize=$BATCH_SIZE, tx_size=$TX_SIZE, R=$R, epoch=$EPOCH"

# 清理端口
echo "清理端口..."
pkill -f ebbflow_server
pkill -f ebbflow_client
sleep 2

# 构建项目
echo "构建EbbFlow项目..."
cd /home/ebbflow
make clean
make build

if [ $? -ne 0 ]; then
    echo "构建失败"
    exit 1
fi

# 启动服务器
echo "启动EbbFlow服务器..."
for i in $(seq 0 $((N-1))); do
    ./bin/ebbflow_server -id $i -n $N -f $((N/3)) &
    sleep 1
done

# 等待服务器启动
echo "等待服务器启动..."
sleep 5

# 启动客户端
echo "启动客户端..."
./bin/ebbflow_client -batch $BATCH_SIZE -txsize $TX_SIZE -count 1000 &

# 等待测试完成
echo "等待测试完成..."
sleep 35

# 停止所有进程
echo "停止所有进程..."
pkill -f ebbflow_server
pkill -f ebbflow_client

# 分析结果
echo "分析测试结果..."
echo "=== CBR协议性能测试完成 ==="

